//
//  DecorateOrdersCenterFooterVIew.m
//  customer
//
//  Created by Holothurian on 2018/11/6.
//  Copyright © 2018年 yinlong. All rights reserved.
//

#import "DecorateOrdersCenterFooterView.h"

@interface DecorateOrdersCenterFooterView()

@property (nonatomic,strong)UIButton *orderBtn;

@end

@implementation DecorateOrdersCenterFooterView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, F_DEVICE_W, 40)];
        backView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:backView];
        
        UIButton *detailBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [detailBtn setTitle:@"查看详情" forState:UIControlStateNormal];
        [detailBtn setTitle:@"查看详情" forState:UIControlStateSelected];
        [detailBtn setTitleColor:[HSPublic colorWithHexString:@"#666666"] forState:UIControlStateNormal];
        [detailBtn setTitleColor:[HSPublic colorWithHexString:@"#666666"] forState:UIControlStateSelected];
        detailBtn.titleLabel.font = Font(12);
        detailBtn.layer.borderWidth = 1;
        detailBtn.layer.cornerRadius = 2;
        detailBtn.layer.masksToBounds = YES;
        detailBtn.layer.borderColor = [HSPublic colorWithHexString:@"#666666"].CGColor;
        [detailBtn addTarget:self action:@selector(detailButtonEvent) forControlEvents:UIControlEventTouchUpInside];
        [backView addSubview:detailBtn];
        [detailBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(backView).offset(-105);
            make.top.equalTo(backView).offset(5);
            make.size.mas_equalTo(CGSizeMake(80, 30));
        }];
        
        UIButton *orderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [orderBtn setTitle:@"支付定金" forState:UIControlStateNormal];
        [orderBtn setTitle:@"支付定金" forState:UIControlStateSelected];
        [orderBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [orderBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [orderBtn setBackgroundColor:[HSPublic colorWithHexString:@"#1F89FF"]];
        orderBtn.titleLabel.font = Font(12);
        orderBtn.layer.cornerRadius = 2;
        orderBtn.layer.masksToBounds = YES;
        [orderBtn addTarget:self action:@selector(payForButtonEvent) forControlEvents:UIControlEventTouchUpInside];
        [backView addSubview:orderBtn];
        [orderBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(backView).offset(-15);
            make.top.equalTo(backView).offset(5);
            make.size.mas_equalTo(CGSizeMake(80, 30));
        }];
        self.orderBtn = orderBtn;
    }
    return  self;
}

- (void)detailButtonEvent{
    if ([self.delegate respondsToSelector:@selector(ordersCenterFooterCurrentOrderLookUpSection:)]) {
        [self.delegate ordersCenterFooterCurrentOrderLookUpSection:self.section];
    }
}
// 1:已预约  2:已确认 3:已支付订单  4:已支付进度款 5:已支付尾款 6:结束
//1:已预约  2:已确认 3:已支付定金   4:已支付尾款 5:结束
- (void)setOrderState:(NSInteger)orderState{
    _orderState = orderState;
    self.orderBtn.enabled = YES;
    if (self.orderState == 2) {
        [self.orderBtn setTitle:@"支付定金" forState:UIControlStateNormal];
        [self.orderBtn setTitle:@"支付定金" forState:UIControlStateSelected];
    }else if (self.orderState == 3){
        if (self.orderType == 0) {
            [self.orderBtn setTitle:@"支付进度款" forState:UIControlStateNormal];
            [self.orderBtn setTitle:@"支付进度款" forState:UIControlStateSelected];
        }else{
            [self.orderBtn setTitle:@"支付尾款" forState:UIControlStateNormal];
            [self.orderBtn setTitle:@"支付尾款" forState:UIControlStateSelected];
        }
    }else if (self.orderState == 4 && self.orderType == 0){
        [self.orderBtn setTitle:@"支付尾款" forState:UIControlStateNormal];
        [self.orderBtn setTitle:@"支付尾款" forState:UIControlStateSelected];
    }else if ((self.orderState == 5&& self.orderType == 0) || (self.orderState == 4 && self.orderType == 1)){
            self.orderBtn.enabled = NO;
            [self.orderBtn setTitle:@"已支付尾款" forState:UIControlStateNormal];
            [self.orderBtn setTitle:@"已支付尾款" forState:UIControlStateSelected];
    }else if (self.orderState == 6 || (self.orderState == 5 && self.orderType == 1)){
         self.orderBtn.enabled = NO;
        [self.orderBtn setTitle:@"已完成" forState:UIControlStateNormal];
        [self.orderBtn setTitle:@"已完成" forState:UIControlStateSelected];
    }
}

- (void)payForButtonEvent{
    if ([self.delegate respondsToSelector:@selector(ordersCenterFooterOrderActionSection:)]) {
        [self.delegate ordersCenterFooterOrderActionSection:self.section];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
